#include "../../../../lib/std.mi"

Global Group frameGroup, content;
Global String x, y, w, h, rx, ry, rw, rh;
Global Title titlebar;

Function setNewGroup(String groupid);
Function padLeft(String s);
Function padRight(String s);

System.onScriptLoaded() {
  frameGroup = getScriptGroup();
  titlebar = frameGroup.getObject("titlebar");
  String param = getParam();
  x = getToken(param, ",", 0);
  y = getToken(param, ",", 1);
  w = getToken(param, ",", 2);
  h = getToken(param, ",", 3);
  rx = getToken(param, ",", 4);
  ry = getToken(param, ",", 5);
  rw = getToken(param, ",", 6);
  rh = getToken(param, ",", 7);
}

frameGroup.onNotify(String cmd, String param, int a, int b) {
  String command = getToken(cmd, ",", 0);
  if (command == "content") {
    setNewGroup(getToken(cmd, ",", 1));
  }
  if (command == "padtitleright") {
    padRight(getToken(cmd, ",", 1));
  }
  if (command == "padtitleleft") {
    padLeft(getToken(cmd, ",", 1));
  }
  if (command == "shade") {
    titlebar.setXmlParam("maximize", "0");
    titlebar.setXmlParam("dblclickaction", "switch;"+getToken(cmd,",",1));
  }
}

setNewGroup(String groupid) {
  content = newGroup(groupid);
  if (!content) {
    messagebox("group \"" + groupid + "\" not found", "ButtonGroup", 0, "");
    return;
  }
  content.setXmlParam("x", x);
  content.setXmlParam("y", y);
  content.setXmlParam("w", w);
  content.setXmlParam("h", h);
  content.setXmlParam("relatx", rx);
  content.setXmlParam("relaty", ry);
  content.setXmlParam("relatw", rw);
  content.setXmlParam("relath", rh);
  content.init(frameGroup);
}

padRight(String s) {
  int v = StringToInteger(s);
  titlebar.resize(titlebar.getGuiX(), titlebar.getGuiY(), titlebar.getGuiW() - v, titlebar.getGuiH());
}

padLeft(String s) {
  int v = StringToInteger(s);
  titlebar.resize(titlebar.getGuiX()+v, titlebar.getGuiY(), titlebar.getGuiW() - v, titlebar.getGuiH());
}




